package com.qf.controller;

import com.qf.dto.R;
import com.qf.dto.UserDto;
import com.qf.entity.TAdminUser;
import com.qf.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.SessionAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/*
杨威
2021/10/26
20:22
*/
@RestController
@RequestMapping("/users")
@Api("用户")
public class UserController {
    private UserService userService;
    @Autowired
    public void setUserService(UserService userService) {
        this.userService = userService;
    }

    @PostMapping("/login")
    @ApiOperation("登录")
    public R login(UserDto userDto, Model model, HttpSession session, HttpServletRequest request){
        System.out.println("登录的controller执行了");
        TAdminUser user = userService.login(userDto);
        session.setAttribute("user",user);
        return R.setOk();
    }
}
